package com.leoman.banner.service.impl;

import com.leoman.banner.dao.BannerDao;
import com.leoman.banner.entity.Banner;
import com.leoman.banner.service.BannerService;
import com.leoman.common.service.impl.GenericManagerImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by 蔡琦 on 2016/6/29 0029.
 *
 */
@Service
public class BannerServiceImpl extends GenericManagerImpl<Banner, BannerDao> implements BannerService {

    @Autowired
    private BannerDao bannerDao;

    @Override
    public Page<Banner> page(Integer pageNum, Integer pageSize) {
        return bannerDao.findAll(new PageRequest(pageNum - 1,pageSize, Sort.Direction.DESC,"id"));
    }

    @Override
    public List<Banner> findByTypeAndCategoryId(Integer type, Long categoryId) {
        return bannerDao.findByTypeAndCategoryId(type, categoryId);
    }
}
